package com.chushouya.controller.manager.admin;


import com.chushouya.common.constant.ServiceType;
import com.chushouya.manager.dto.admin.bannerposition.*;
import com.general.framework.core.enums.BusinessType;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.Log;
import com.chushouya.manager.service.admin.BannerPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping(ServiceType.PLATFORM + "/bannerPosition")
@Api(tags = "banner位置管理")
public class BannerPositionController {

    @Resource
    private BannerPositionService positionService;

    @GetMapping("/page")
    @ApiOperation("banner分页列表")
    public Response<PageResult<BannerPositionListDTO>> page(BannerPositionQuery query) {
        return Response.success(positionService.selectPage(query));
    }

    @GetMapping("/list")
    @ApiOperation("banner分页列表")
    public Response<List<BannerPositionListDTO>> list(BannerPositionQuery query) {
        return Response.success(positionService.selectList(query));
    }

    @GetMapping("/detail")
    @ApiOperation("导航栏详情")
    public Response<BannerPositionDetailDTO> detail(Long positionId) {
        return Response.success(positionService.detail(positionId));
    }

    @PostMapping("/add")
    @ApiOperation("添加导航栏")
    @Log(businessType = BusinessType.INSERT)
    public Response<Void> save(@RequestBody @Valid BannerPositionSaveDTO dto) {
        positionService.save(dto);
        return Response.success();
    }

    @PostMapping("/edit")
    @ApiOperation("更新导航栏")
    @Log(businessType = BusinessType.UPDATE)
    public Response<Void> update(@RequestBody @Valid BannerPositionUpdateDTO dto) {
        positionService.update(dto);
        return Response.success();
    }

    @PostMapping("/remove")
    @ApiOperation("删除导航栏")
    @Log(businessType = BusinessType.DELETE)
    public Response<Void> remove(Long positionId) {
        positionService.remove(positionId);
        return Response.success();
    }

}
